package com.kly.module_base.utils

/**
 * @ClassName: SaveDeviceUtil
 * @Description:
 * @Author: You
 */
class SaveDeviceUtil {
    companion object {
        //appsFlyerUID
        const val APPS_FLYER_UID = "apps_flyer_uid"
        //token
        const val TOKEN = "token"
        //api的请求域名
        const val API_ROOT_DOMAIN = "api_root_domain"

        /**
         * 获取token
         */
        fun getToken(): String? {
            return MMKVUtil.mmkv?.decodeString(TOKEN, null)
        }

        /**
         * 保存token
         */
        fun saveToken(token: String?) {
            if (token.isNullOrBlank()) {
                return
            }
            MMKVUtil.mmkv?.encode(TOKEN, token)
        }

        /**
         * 获取token
         */
        fun getAppsFlyerUID(): String? {
            return MMKVUtil.mmkv?.decodeString(APPS_FLYER_UID, null)
        }

        /**
         * 保存token
         */
        fun saveAppsFlyerUID(appsFlyerUID: String?) {
            if (appsFlyerUID.isNullOrBlank()) {
                return
            }
            MMKVUtil.mmkv?.encode(APPS_FLYER_UID, appsFlyerUID)
        }

        /**
         * 获取root_domain
         */
        fun getRootDomain(): String {
            return MMKVUtil.mmkv?.decodeString(API_ROOT_DOMAIN, "") ?: ""
        }

        /**
         * 保存root_domain
         */
        fun saveRootDomain(rootDomain: String?) {
            if (rootDomain.isNullOrBlank()) {
                return
            }
            MMKVUtil.mmkv?.encode(API_ROOT_DOMAIN, rootDomain)
        }

        /**
         * 清空用户相关信息
         */
        fun clearUserInf() {
            MMKVUtil.mmkv?.remove("selectBankBean")
            MMKVUtil.mmkv?.remove(TOKEN)
        }
    }
}